<?php
apf_require_class("Bll_BLL");
class Bll_Portal_Message extends BLL {

    /**
     * 获取一条记录
     * @param int $user_id
     * @return array
     */
    public function get_message($user_id){
        if (!$user_id || !is_numeric($user_id)){
            return array();
        }
        $user_id = intval($user_id);
        return $this->get_message_dao()->find_row(array('user_id'=>$user_id));
    }
    /**
     * 添加
     * @param array $data
     * @return 0|insert_id
     */
    public function add_message($data){
        if(is_array($data) && $data['user_id'] && $data['content']){
            $message = $this->get_message($data['user_id']);
            if($message){
                return $this->get_message_dao()->update($data,array('user_id'=>$data['user_id']));
            }else{
                return $this->get_message_dao()->insert($data);
            }
        }else{
            return 0;
        }
    }


    /**
     * 获取列表
     */
    public function get_all_messages(){
        return $this->get_message_dao()->find(array('1=?'=>1),null,0,0);
    }

    /**
     * @return Dao_Portal_Message
     */
    private function get_message_dao(){
        return $this->get_dao('Dao_Portal_Message');
    }

}